package com.zky.DAO.impl;

import java.util.ArrayList;
import java.util.List;




import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.zky.DA0.Users1Dao;
import com.zky.common.HibernateSessionFactory;

import com.zky.entity.Users1;

public class Users1DaoImp implements Users1Dao {
	public List<Users1> list=new ArrayList<Users1>();
	
	
	public void save(Users1 users1){
		 Session session = HibernateSessionFactory.getSession();
		 Transaction transaction = session.beginTransaction();
		 try {
			session.save(users1);
			 transaction.commit();
			 //session.close();
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
		    session.close();
			
		}
		  //return null;	
	}
	
	public List<Users1> findAll2(String name) {
		 Session session = HibernateSessionFactory.getSession();
		 Transaction transaction = session.beginTransaction();		
		  try{
			  String hql="from Users1 as muser where muser.username=?";
			  Query query=session.createQuery(hql);
			  query.setString(0, name);
			   list=query.list();
				if (null == list || list.size() == 0) {
			    	System.out.print("没有");
			    }
				else{
					System.out.print("正确");
				}
			   transaction.commit();
			   
			   }catch(Exception e){
			    e.printStackTrace();
			   }finally{
			    session.close();
		
	}
		return list;
	}
	public List<Users1> findAll3(String name) {
		 Session session = HibernateSessionFactory.getSession();
		 Transaction transaction = session.beginTransaction();		
		  try{
			  String hql="from Users1 as muser where muser.username=?";
			  Query query=session.createQuery(hql);
			  query.setString(0, name);
			   list=query.list();
				if (null == list || list.size() == 0) {
					System.out.print("正确");
			    }
				else{
					System.out.print("错误");
				}
			   transaction.commit();
			   
			   }catch(Exception e){
			    e.printStackTrace();
			   }finally{
			    session.close();
		
	}
		return list;
	}
}
